package com.nbsaas.boot.project.controller;

import com.nbsaas.boot.project.api.apis.ProjectApi;
import com.nbsaas.boot.project.api.domain.request.ProjectRequest;
import com.nbsaas.boot.project.api.domain.request.ProjectSearch;
import com.nbsaas.boot.project.api.domain.response.ProjectResponse;
import com.nbsaas.boot.project.api.domain.simple.ProjectSimple;
import com.nbsaas.boot.project.ext.apis.ProjectExtApi;
import com.nbsaas.boot.project.ext.domain.request.ProjectExtRequest;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/project")
public class ProjectController {


    @Resource
    private ProjectApi projectApi;

    @Resource
    private ProjectExtApi projectExtApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("project:search")
    @PostMapping("/search")
    public PageResponse<ProjectSimple> search(@RequestBody ProjectSearch request) {
        return projectApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("project:list")
    @PostMapping("/list")
    public ListResponse<ProjectSimple> list(@RequestBody ProjectSearch request) {
        return projectApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("project:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<?> create(@RequestBody @Validated(AddOperator.class) ProjectExtRequest request) {
        return projectExtApi.createExt(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("project:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<ProjectResponse> update(@RequestBody @Validated(UpdateOperator.class) ProjectRequest request) {
        return projectApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("project:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) ProjectRequest request) {
        return projectApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("project:view")
    @PostMapping("/view")
    public ResponseObject<ProjectResponse> view(@RequestBody @Validated(ViewOperator.class) ProjectRequest request) {
        return projectApi.view(request);
    }
}